package com.scrcu.core.batch.cotroller;

import com.alibaba.fastjson.JSONObject;
import com.boarsoft.common.util.RandomUtil;
import com.scrcu.core.batch.biz.BatchAppBiz;
import com.scrcu.core.batch.entity.BatchApp;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @Description:
 * @Author: 刘超
 * @Date: 2023-05-12 10:57
 */
@RestController
@RequestMapping("/batchApp")
public class BatchAppBizController {
    @Autowired
    BatchAppBiz batchAppBiz;

    @GetMapping("/save")
    public String save(){

        BatchApp batchApp = new BatchApp();
        batchApp.setId(RandomUtil.genUUID());
        batchApp.setAddr("127.0.0.1:8081");
        batchApp.setCatalog("test");
        batchApp.setGroup("testGroup");
        Object save = batchAppBiz.save(batchApp);
        return "success, result: "+ JSONObject.toJSONString(save);
    }

    @GetMapping("/get")
    public String get(){
        BatchApp batchApp = batchAppBiz.get("127.0.0.1:8081");
        return JSONObject.toJSONString(batchApp);
    }

    @GetMapping("/delete")
    public String delete(){
        batchAppBiz.delete("127.0.0.1:8081");
        return "success";
    }

    @GetMapping("/getList")
    public String selectList(){
        List<BatchApp> list = batchAppBiz.list();
        return JSONObject.toJSONString(list);
    }


}
